///geo Module Driver Interface definitions
//

#ifndef GEO__MODULE_INC
#define GEO__MODULE_INC

#include <fcntl.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#ifdef linux
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#else
#include <windows.h>
#include <io.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <string.h>
#include <arpa/inet.h>
#include <syslog.h>
#include "geousbhid.h"
#include "fmaa.h"

#define IFCONFIG_STRING_DEPTH 1024*1024

using namespace std;

typedef struct sgeoStats {
    float geo_control_reset;
    float geo_control_status;
    float TOTAL;
    float TOTAL_COMPOSITE;
}type_sgeoStats;

typedef enum eGEOBusTypes {
    GEO_ETHERNET,
    GEO_USB,
    GEO_FS,
    GEO_SOI,
    GEO_RTC,
    NUM_GEO_BUS_TYPES
}type_eGEOBusTypes;

typedef enum egeoStatus {
    GEO_STATUS_BUSY = 0x01,
    GEO_STATUS_POWER_ERROR = 0x2,
    GEO_RESERVED
}type_egeoStatus;

typedef enum egeoError {
    GEO_ERROR_TYPE2 = -1,
    GEO_ERROR_TYPE3 = -1,
    GEO_ERROR_TYPE4 = -1,
    GEO_ERROR_TYPE5 = -1,
    GEO_ERROR_TYPE6 = -1,
    GEO_ERROR_TYPE7 = -1,
    GEO_ERROR_TYPE8 = -1,
    NUM_GEO_ERRORS = 8
}type_egeoError;

class Cgeo : public CCgeousbhid
{
public:

    Cgeo();
    ~Cgeo();

    //GEO
    Cfmaa fmaa;

    void TestStringOutput();
    int reset();
    int status();
    int geo_control_Initialise(char *filename);
    int geo_control_Close();
    int geo_read(unsigned char *msg);
    int geo_write(unsigned char *msg);

    ///geo Module functions
    float ProcessStats(char *description_string, struct timespec *tp_start, struct timespec *tp_end);
    void AddToStats(unsigned char *msg);

    int run_unit_test();

    ///Parameters & handle for geo Module Statistics
    struct sgeoStats GEO_Stats, GEO_StatsAvg;
    float TOTAL_COMPOSITE, TOTAL;
    FILE *fp_out;

    // This is the handle and the id of the thread
    pthread_t m_thread;

    egeoStatus hw_status;
    unsigned int *hw_blocked_count;

	unsigned char *geo_buf, geo_addr;
	int geo_byte_count;
	eGEOBusTypes GEO_BUS;

protected:

private:

    ///Generic declarations
    unsigned int status_, j, k;
    int i;

    ///geo Module timing parameters
    clockid_t clk_id;
    struct timespec tp_start, tp_end, tp_start_reset;

    static void *geoThreadL(void *data);
    struct thread_fun_args
    {
    Cgeo* This ;
    void* actual_arg ;
    thread_fun_args( Cgeo* t, void* p )
        : This(t), actual_arg(p) {}
    };

    bool bgeoThread_Running;
    int pfd;

    unsigned int hw_ptr;
};

#endif ///GEO__MODULE_INC









